//package com.caishi.lkx.common.fliter;
//
//import cn.hutool.core.util.StrUtil;
//import cn.hutool.crypto.symmetric.AES;
//import com.caishi.lkx.common.AclResultCode;
//import com.caishi.lkx.common.context.Context;
//import com.caishi.lkx.common.context.RequireContext;
//import com.caishi.lkx.common.context.UserContext;
//import com.caishi.lkx.common.ienum.DeviceType;
//import com.zzw.common.exception.BizException;
//import com.zzw.common.util.SpringMVCUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.annotation.Order;
//import org.springframework.util.AntPathMatcher;
//import org.springframework.web.method.HandlerMethod;
//import org.springframework.web.servlet.HandlerMapping;
//
//import javax.annotation.Resource;
//import javax.servlet.*;
//import javax.servlet.http.Cookie;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.nio.charset.StandardCharsets;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Map;
//
///**
// * @author by keray
// * date:2021/4/1 10:49 上午
// */
//@Slf4j
//@Configuration
//@Order(Integer.MIN_VALUE + 102)
//public class ContextFilter implements Filter {
//
//    private static final AES AES = new AES("05ee4559b3db2ab9a1f5d86a316c90d4".getBytes(StandardCharsets.UTF_8));
//    private static final AntPathMatcher pathMatcher = new AntPathMatcher();
//
//    @Resource
//    private Context context;
//
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//        HttpServletRequest httpRequest = (HttpServletRequest) request;
//        Object handler = httpRequest.getAttribute(HandlerMapping.BEST_MATCHING_HANDLER_ATTRIBUTE);
//
//        if (handler instanceof HandlerMethod) {
//            HandlerMethod handlerMethod = (HandlerMethod) handler;
//
//            // 判断方法或类上是否有 @RequireContextCheck 注解
//            if (handlerMethod.hasMethodAnnotation(RequireContext.class) ||
//                    handlerMethod.getBeanType().isAnnotationPresent(RequireContext.class)) {
//
//                // 执行 context 设置逻辑
//                Long groupId = getGid(httpRequest);
//                context.setGroupId(groupId);
//            }
//        }
//
//        chain.doFilter(request, response);
//    }
//
//    public static Long getGid(HttpServletRequest request) throws IOException {
//        String aesStr = request.getHeader(TokenFilter.TOKEN_USER_GROUP);
//        if (aesStr == null) {
//            throw new IOException("平台id不能为空");
//        }
//        aesStr = AES.decryptStr(aesStr);
//        return Long.parseLong(aesStr);
//    }
//
//
//
//}
